package com.gorkr.labuladong.data_struct.array.binary_search;

/**
 * @author gorkr
 * @date 2022/06/03 19:04
 **/
public class E704BinarySearch {

    public int search(int[] nums, int target) {

        int left = 0, right = nums.length-1;
        int mid;
        while(left<=right){
            mid = (left+right)/2;
            if(nums[mid]==target){
                return mid;
            } else if (nums[mid]<target) {
                left = mid+1;
            }else {
                right = mid-1;
            }
        }
        return -1;

    }
}
    